home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / FieldList.h < prev    next >
C/C++ Source or Header  |  2000-05-09  |  6KB  |  276 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/FieldList.h,v 41.11 2000/05/09 20:33:33 mlemos Exp $
  3.  *
  4.  * FieldList.h
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995-1996 Jaba Development.
  8.  * (C) Copyright 1995-1996 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * This is a simple subclass of the Listview class which
  12.  * will allow drops from another Listview object, positioned
  13.  * drops and sortable drops.
  14.  *
  15.  * It is included in the demonstration programs that make
  16.  * use of it.
  17.  *
  18.  * Tags:
  19.  *  FL_DropAccept -- A pointer to the listview object from
  20.  *    which drops will be accepted. Ofcourse
  21.  *    you are responsible to make sure that
  22.  *    the entries of this object are of the
  23.  *    same format as the entries of the
  24.  *    target object.
  25.  *
  26.  *  FL_SortDrops -- When TRUE the class will sort the drops
  27.  *    automatically. When FALSE the drops may
  28.  *    be positioned by the user.
  29.  *
  30.  * $Log: FieldList.h,v $
  31.  * Revision 41.11  2000/05/09 20:33:33  mlemos
  32.  * Bumped to revision 41.11
  33.  *
  34.  * Revision 1.2  2000/05/09 19:58:52  mlemos
  35.  * Merged with the branch Manuel_Lemos_fixes.
  36.  *
  37.  * Revision 1.1.2.2  1999/02/19 05:03:52  mlemos
  38.  * Added support to build with Storm C.
  39.  *
  40.  * Revision 1.1.2.1  1998/02/28 17:45:52  mlemos
  41.  * Ian sources
  42.  *
  43.  *
  44.  */
  45.  
  46. #include <proto/utility.h>
  47.  
  48. /*
  49.  *    Tags for this subclass.
  50.  */
  51. #define FL_AcceptDrop        TAG_USER+0x2000         /* IS--- */
  52. #define FL_SortDrops        TAG_USER+0x2001         /* IS--- */
  53.  
  54. /*
  55.  *    Object instance data.
  56.  */
  57. typedef struct {
  58.     Object            *fld_Accept;        /* Accept drops from this object. */
  59.     BOOL             fld_SortDrops;         /* Auto-sort drops. */
  60. } FLD;
  61.  
  62. /*
  63.  *    Some easy type-casts.
  64.  */
  65. #define SET(x)        (( struct opSet * )x )
  66. #define QUERY(x)    (( struct bmDragPoint * )x )
  67. #define DROP(x)         (( struct bmDropped * )x )
  68.  
  69. /*
  70.  *    Set attributes.
  71.  */
  72. STATIC ASM VOID SetFLAttr( REG(a0) FLD *fld, REG(a1) struct TagItem *attr )
  73. {
  74.     struct TagItem        *tag, *tstate = attr;
  75.  
  76.     /*
  77.      *    Scan attribute list.
  78.      */
  79.     while ( tag = NextTagItem( &tstate )) {
  80.         switch ( tag->ti_Tag ) {
  81.  
  82.             case    FL_AcceptDrop:
  83.                 fld->fld_Accept = ( Object * )tag->ti_Data;
  84.                 break;
  85.  
  86.             case    FL_SortDrops:
  87.                 fld->fld_SortDrops = tag->ti_Data;
  88.                 break;
  89.         }
  90.     }
  91. }
  92.  
  93. /*
  94.  *    Class dispatcher. Remember! NOSTACKCHECK or __interrupt for
  95.  *    SAS users!
  96.  */
  97. #ifdef __STORM__
  98. STATIC ULONG SAVEDS ASM
  99. #else
  100. STATIC SAVEDS ASM ULONG
  101. #endif
  102. DispatchFL( REG(a0) Class *cl, REG(a2) Object *obj, REG(a1) Msg msg )
  103. {
  104.     FLD               *fld;
  105.     APTR            entry;
  106.     struct IBox           *ib;
  107.     ULONG            rc, spot;
  108.  
  109.     /*
  110.      *    What do they want...
  111.      */
  112.     switch ( msg->MethodID ) {
  113.  
  114.         case    OM_NEW:
  115.             /*
  116.              *    Let the superclass make the object.
  117.              */
  118.             if ( rc = DoSuperMethodA( cl, obj, msg )) {
  119.                 /*
  120.                  *    Get instance data.
  121.                  */
  122.                 fld = ( FLD * )INST_DATA( cl, rc );
  123.  
  124.                 /*
  125.                  *    Set defaults.
  126.                  */
  127.                 fld->fld_Accept    = NULL;
  128.                 fld->fld_SortDrops = FALSE;
  129.  
  130.                 /*
  131.                  *    Get attributes.
  132.                  */
  133.                 SetFLAttr( fld, SET( msg )->ops_AttrList );
  134.             }
  135.             break;
  136.  
  137.         case    OM_SET:
  138.             /*
  139.              *    First the superclass.
  140.              */
  141.             rc = DoSuperMethodA( cl, obj, msg );
  142.  
  143.             /*
  144.              *    Then we have a go.
  145.              */
  146.             fld = ( FLD * )INST_DATA( cl, obj );
  147.             SetFLAttr( fld, SET( msg )->ops_AttrList );
  148.             break;
  149.  
  150.         case    BASE_DRAGQUERY:
  151.             /*
  152.              *    We only allow drops from ourselves and from
  153.              *    the object specified with FL_AcceptDrop.
  154.              */
  155.  
  156.             /*
  157.              *    We let the superclass worry about it when
  158.              *    the requesting object request is us.
  159.              */
  160.             if ( QUERY( msg )->bmdp_Source == obj )
  161.                 return( DoSuperMethodA( cl, obj, msg ));
  162.  
  163.             /*
  164.              *    Get instance data.
  165.              */
  166.             fld = ( FLD * )INST_DATA( cl, obj );
  167.  
  168.             /*
  169.              *    Is it the object specified with FL_AcceptDrop?
  170.              */
  171.             if ( QUERY( msg )->bmdp_Source == fld->fld_Accept ) {
  172.                 /*
  173.                  *    Get the listview class list bounds.
  174.                  */
  175.                 GetAttr( LISTV_ViewBounds, obj, ( ULONG * )&ib );
  176.  
  177.                 /*
  178.                  *    Mouse inside view bounds? Since the superclass
  179.                  *    starts sending this message when the mouse goes
  180.                  *    inside the hitbox we only need to check if it
  181.                  *    is not located right of the view area.
  182.                  */
  183.                 if ( QUERY( msg )->bmdp_Mouse.X < ib->Width )
  184.                     return( BQR_ACCEPT );
  185.             }
  186.  
  187.             /*
  188.              *    Screw the rest...
  189.              */
  190.             rc = BQR_REJECT;
  191.  
  192.             break;
  193.  
  194.         case    BASE_DROPPED:
  195.             /*
  196.              *    If the drop comes from ourself we let the
  197.              *    superclass handle it.
  198.              */
  199.             if ( DROP( msg )->bmd_Source == obj )
  200.                 return( DoSuperMethodA( cl, obj, msg ));
  201.  
  202.             /*
  203.              *    Get instance data.
  204.              */
  205.             fld = ( FLD * )INST_DATA( cl, obj );
  206.  
  207.             /*
  208.              *    Find out where the drop was made.
  209.              */
  210.             GetAttr( LISTV_DropSpot, obj, &spot );
  211.  
  212.             /*
  213.              *    Simply pick up all selected entries
  214.              *    from the dragged object.
  215.              */
  216.             while ( entry = ( APTR )FirstSelected( DROP( msg )->bmd_Source )) {
  217.                 /*
  218.                  *    Set it on ourselves. We insert it when we are
  219.                  *    not sortable. We add them sorted when we are
  220.                  *    sortable.
  221.                  */
  222.                 if ( fld->fld_SortDrops == FALSE ) DoMethod( obj, LVM_INSERTSINGLE, NULL, spot, entry, LVASF_SELECT );
  223.                 else                   DoMethod( obj, LVM_ADDSINGLE, NULL, entry, LVAP_SORTED, LVASF_SELECT );
  224.  
  225.                 /*
  226.                  *    Remove it from the dropped object.
  227.                  */
  228.                 DoMethod( DROP( msg )->bmd_Source, LVM_REMENTRY, NULL, entry );
  229.             }
  230.  
  231.             /*
  232.              *    Refresh the dragged object. We do not have to
  233.              *    refresh ourselves since the base class will
  234.              *    do this for us when we are deactivated.
  235.              */
  236.             BGUI_DoGadgetMethod( DROP( msg )->bmd_Source,
  237.                          DROP( msg )->bmd_SourceWin,
  238.                          DROP( msg )->bmd_SourceReq,
  239.                          LVM_REFRESH, NULL );
  240.             rc = 1;
  241.             break;
  242.  
  243.         default:
  244.             /*
  245.              *    Let's the superclass handle the rest.
  246.              */
  247.             rc = DoSuperMethodA( cl, obj, msg );
  248.             break;
  249.     }
  250.     return( rc );
  251. }
  252.  
  253. /*
  254.  *    Simple class initialization.
  255.  */
  256. Class *InitFLClass( void )
  257. {
  258.     Class            *super, *cl = NULL;
  259.  
  260.     /*
  261.      *    Obtain the ListviewClass pointer which
  262.      *    will be our superclass.
  263.      */
  264.     if ( super = BGUI_GetClassPtr( BGUI_LISTVIEW_GADGET )) {
  265.         /*
  266.          *    Create the class.
  267.          */
  268.         if ( cl = MakeClass( NULL, NULL, super, sizeof( FLD ), 0L ))
  269.             /*
  270.              *    Setup dispatcher.
  271.              */
  272.             cl->cl_Dispatcher.h_Entry = ( HOOKFUNC )DispatchFL;
  273.     }
  274.     return( cl );
  275. }
  276.